<?php

namespace App\Transformers\StoreCoupon;

use App\Models\StoreCouponUser;
use Carbon\Carbon;
use League\Fractal\TransformerAbstract;

class StoreCouponUserTransformer extends TransformerAbstract
{
    public function transform(StoreCouponUser $data){
        return [
            'id' => $data->id,
            'cid' => $data->cid ?? '',
            'user_id' => $data->user_id ?? '',
            'coupon_title' => $data->coupon_title ?? '',
            'coupon_price' => $data->coupon_price ?? '',
            'use_min_price' => $data->use_min_price ?? '',
            'add_time' => $data->add_time ? $data->add_time->format("Y-m-d H:i:s") : '',
            'end_time' => $data->end_time ? $data->end_time->format("Y-m-d H:i:s") : '',
            'effective_time' => Carbon::parse ($data->add_time)->diffInDays($data->end_time, false),
            'use_time' => $data->use_time ?? '',
            'type' => $data->type ?? '',
            'status' => $data->statusLet[$data->status] ?? '',
            'is_fail' => $data->is_fail ?? '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'user' => $data->user ?? '',
        ];
    }

}
